package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.bean.NewFragmentBean;
import com.example.fruit.R;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by User on 2015/6/30.
 */
public class CartAdapter  extends BaseAdapter{

    private List<NewFragmentBean> datas;
    private ListView listView;
    private Context context;
    public CartAdapter(Context context, List<NewFragmentBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return datas.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder vHolder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_fragment_allguoshi, null);
            vHolder=new ViewHolder();
            ViewUtils.inject(vHolder, convertView);

            convertView.setTag(vHolder);
        }else{
            vHolder=(ViewHolder)convertView.getTag();
            vHolder.imageView.setImageResource(R.drawable.ic_launcher);

        }
        final NewFragmentBean cData = datas.get(position);
        vHolder.titleTv.setText(cData.getProduct_name());
        vHolder.title2Tv.setText(cData.getVolume());

        //"http://api.yi18.net/cook/list";


        vHolder.priceTv.setText("￥" + cData.getPrice());

        String imgPath =  cData.getThum_photo();


        BitmapUtils bitmapUtils=new BitmapUtils(context);
        bitmapUtils.display(vHolder.imageView,imgPath);

        return convertView;
    }
    class ViewHolder{
        @ViewInject(R.id.title_cart)
        TextView titleTv;
        @ViewInject(R.id.title2_cart)
        TextView title2Tv;
       @ViewInject(R.id.price1_cart)
        TextView priceTv;
        @ViewInject(R.id.img_cart)
        ImageView imageView;
    }
}
